package py.org.atom.seam.entity;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.hibernate.validator.Length;

import py.org.atom.seam.util.SHA1;
import py.org.atom.seam.util.Sys;



@MappedSuperclass
public class BaseUser extends InsUpdDisAudit{
	
	@Id
	@Column(name = Sys.ID_COLNAME, unique = true, nullable = false, length = Sys.ID_MAXLEN)
	@Length(max=Sys.ID_MAXLEN, min=Sys.ID_MINLEN)
	protected String id;
	
	@Column(name = Sys.PASSWORD_COLNAME, length = Sys.PASSWORD_MAXLEN)
	protected String pwd;		
	
	@Column(name = Sys.STATUS_COLNAME, length = 1)
	protected String status;
	
	@Column(name = Sys.LDAP_COLNAME, length = 1)
	protected String ldap;	
	
	@Transient
	protected String nakedPwd;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}	
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.nakedPwd = pwd;
		if(this.ldap != null && !this.ldap.trim().equals("Y")){
			if(pwd == null)
				this.pwd = SHA1.getPwd(Sys.property("password.default"));
			else
				this.pwd = SHA1.getPwd(pwd);
		}
		if(this.ldap.trim().equals("Y"))
			this.pwd = pwd;
	}
	
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getLdap() {
		return ldap;
	}
	public void setLdap(String ldap) {
		this.ldap = ldap;
	}

	public String getNakedPwd(){
		return this.nakedPwd;
	}
}
